let instance

/**
 * 统一的音效管理器
 */
export default class Music {
  constructor() {
    if ( instance )
      return instance

    instance = this

    var bgmAudio = wx.createInnerAudioContext()
    bgmAudio.autoplay = true
    bgmAudio.loop = true
    bgmAudio.src  = 'audio/bgm.mp3'
    this.bgmAudio = bgmAudio

    this.blockAudio     = new Audio()
    this.blockAudio.src = 'audio/blockwood.mp3'

    this.playerAudio     = new Audio()
    this.playerAudio.src = 'audio/player2.mp3'

    this.gameoverAudio = new Audio()
    this.gameoverAudio.src = 'audio/gameover.mp3'

    this.selectAudio = new Audio()
    this.selectAudio.src = 'audio/select.mp3'

    this.againAudio = new Audio()
    this.againAudio.src = 'audio/again.mp3'

  }

  playBlock() {
    this.blockAudio.currentTime = 0
    this.blockAudio.play()
  }

  playPlayer() {
    this.playerAudio.currentTime = 0
    this.playerAudio.play()
  }

  playGameOver() {
    this.gameoverAudio.currentTime = 0
    this.gameoverAudio.play()
  }

  playSelect() {
    this.selectAudio.currentTime = 0
    this.selectAudio.play()
  }

  playAgain() {
    this.againAudio.currentTime = 0
    this.againAudio.play()
  }
}
